﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Data;
using MyLib;
using Portal.Entity;
//using Portal.Interface;
using Portal.Logic;
using ProcessControl;
using ProcessControl.Interface;
using ProcessControl.Entity;
using System.Collections;
using Portal.Interface;

namespace POProcess
{

    public partial class NewPOProcess : System.Web.UI.Page
    {
        IPR _pr = ServiceContainer.Instance().GetService<IPR>(); 
        protected void Page_Load(object sender, EventArgs e)
        {            
            if (!IsPostBack)
            {
                BindCurrency();  //币种
                BindTax();      //税别
                hfResult.Value = "0";
            }
            ((ButtonList)this.ButtonList1).AfterSubmit += new System.ComponentModel.CancelEventHandler(NewPOProcess_AfterSubmit);
        }
        void NewPOProcess_AfterSubmit(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //throw new NotImplementedException();
            //更新余额
            IBuget buget = ServiceContainer.Instance().GetService<IBuget>();

            foreach (RepeaterItem ri in fld_detail_PROC_PO_DT.Items)
            {
                //DropDownList ddlMATERIALNAME = ri.FindControl("ddl_MATERIALNAME") as DropDownList;
                //ddlMATERIALNAME.Attributes.Remove("OnSelectedIndexChanged");
                //ddlMATERIALNAME.Items.Clear();

                int TotalQty = 0;
                int i_Qty = 0;
                string RowID = ((DropDownList)ri.FindControl("ddl_MATERIALNAME")).SelectedValue;    //PR行号              
                string MaterialName = ((TextBox)ri.FindControl("fld_MATERIALNAME")).Text;    //物料名称                
                string bugCode = ((TextBox)ri.FindControl("fld_BUDGETNUMBER")).Text;   //预算编号
                double amount = ConvertUtil.ToDouble(((TextBox)ri.FindControl("fld_TOTALCOST")).Text);
                string CurrentQty = ((TextBox)ri.FindControl("fld_SHORTFALL")).Text;   //当前行订单量    

                if (fld_PONO.Text.Contains(","))
                {
                    //string[] fm = fld_PRFORMID.Text.Split(',');
                    //string str = "";
                    //foreach (string formId in fm)
                    //{
                    //str += " or DOCUMENTNO= '" + ss + "'";           
                    bool strName = GetPRDetail(MaterialName, CurrentQty);
                    int UsedQty = int.Parse(hfPRUsedQty.Value);       //PR中已使用的订单量
                    if (strName == true)
                    {
                        i_Qty = int.Parse(CurrentQty);   //当前输入的数量
                        TotalQty += i_Qty;
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty)    //判断如果第一次用户输入的数量就与PR的总数量相等时，执行该判断
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, hfCurrFormID.Value.Trim());   //
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty + UsedQty)   //判断如果当前输入的数量加上已使用的数据，刚好等于PR的总数量，则更新行数据状态
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, hfCurrFormID.Value.Trim());
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) > TotalQty)   //判断如果当前输入的数量小于PR的总数量时，则更新当前输入的数量。
                    {
                        bool IsSuccess = _pr.UpdateRowsUsedQtyAndPR(bugCode, hfCurrFormID.Value.Trim(), TotalQty + UsedQty, MaterialName);
                    }
                    //}
                }
                else
                {

                    bool strName = GetPRData(RowID, MaterialName, CurrentQty);
                    int UsedQty = int.Parse(hfPRUsedQty.Value);       //PR中已使用的订单量
                    if (strName == true)
                    {
                        i_Qty = int.Parse(CurrentQty);   //当前输入的数量
                        TotalQty += i_Qty;
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty)    //判断如果第一次用户输入的数量就与PR的总数量相等时，执行该判断
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, fld_PRFORMID.Text.Trim());   //
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty + UsedQty)   //判断如果当前输入的数量加上已使用的数据，刚好等于PR的总数量，则更新行数据状态
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, fld_PRFORMID.Text.Trim());
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) > TotalQty)   //判断如果当前输入的数量小于PR的总数量时，则更新当前输入的数量。
                    {
                        bool IsSuccess = _pr.UpdateRowsUsedQty(bugCode, fld_PRFORMID.Text.Trim(), TotalQty + UsedQty, int.Parse(RowID));
                    }
                }
            }
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            UserInfo userInfo = Page.FindControl("UserInfo1") as UserInfo;
            userInfo.AddNewRow(fld_detail_PROC_PO_DT);
        }

        protected void ddlMaterial_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlMaterial = (DropDownList)sender;
            TextBox txtSPEC = (TextBox)ddlMaterial.Parent.FindControl("fld_SPEC");
            TextBox txtITEMNUMBER = (TextBox)ddlMaterial.Parent.FindControl("fld_BUDGETNUMBER");   //预算编号
            TextBox txtMATERIALNAME = (TextBox)ddlMaterial.Parent.FindControl("fld_MATERIALNAME");
            //DropDownList ddlCOSTCATEGORY = (DropDownList)ddlMaterial.Parent.FindControl("COSTCATEGORY");  //成本类别
            TextBox txtCOSTCATEGORY = (TextBox)ddlMaterial.Parent.FindControl("fld_COSTCATEGORY");
            TextBox txtHORTFALL = (TextBox)ddlMaterial.Parent.FindControl("fld_SHORTFALL");    //订单数量
            TextBox txtPRAMOUNT = (TextBox)ddlMaterial.Parent.FindControl("fld_PRAMOUNT");    //PR申请金额
            TextBox txtPRINfo = (TextBox)ddlMaterial.Parent.FindControl("fld_PRINFO");      //PR申请信息
            TextBox txtPRRequester = (TextBox)ddlMaterial.Parent.FindControl("fld_PRREQUESTER");      //PR申请人
            TextBox txtPRRequesterAccount = (TextBox)ddlMaterial.Parent.FindControl("fld_PRREQUESTERACCOUNT");      //PR申请人账号
            TextBox txtPartNO = (TextBox)ddlMaterial.Parent.FindControl("fld_PARTNO");      //品号
            TextBox txtUM = (TextBox)ddlMaterial.Parent.FindControl("fld_METER");      //单位

            string StrSQL = "";
            if (fld_PONO.Text.Contains(","))
            {
                StrSQL = "select T.ITEMNUMBER,T.SPEC,T.COSTCATEGORY,P.DOCUMENTNO,T.QUANTITY,T.USEDQUANTITY,T.PRODUCTNAME,T.ESTIMATEDPRICE,P.COSTCENTER,P.PRODUCTLINE,P.APPLICANT,T.PRODUCTNO from PROC_PURCHASEREQUEST_DT as T "
                + " inner join dbo.PROC_PURCHASEREQUEST P on P.FORMID=T.FORMID "
                    //+ "  where DOCUMENTNO='" + fld_PONO.Text.Trim() + "'  and ID='" + ddlMaterial.SelectedValue + "'";
                 + "  where DOCUMENTNO='" + ddlMaterial.SelectedValue.Trim() + "'  and PRODUCTNAME='" + txtMATERIALNAME.Text.Trim() + "'";
            }
            else
            {
                StrSQL = "select T.ITEMNUMBER,T.SPEC,T.COSTCATEGORY,P.DOCUMENTNO,T.QUANTITY,T.USEDQUANTITY,T.PRODUCTNAME,T.ESTIMATEDPRICE,P.COSTCENTER,P.PRODUCTLINE,P.APPLICANT,T.PRODUCTNO from PROC_PURCHASEREQUEST_DT as T "
                   + " inner join dbo.PROC_PURCHASEREQUEST P on P.FORMID=T.FORMID "
                   + "  where DOCUMENTNO='" + fld_PONO.Text.Trim() + "'  and ID='" + ddlMaterial.SelectedValue + "'";
                    
            }
            DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(StrSQL);
            if (dt.Rows.Count > 0)
            {
                txtITEMNUMBER.Text = dt.Rows[0]["ITEMNUMBER"].ToString();  //预算编号
                txtSPEC.Text = dt.Rows[0]["SPEC"].ToString();
                //ddlCOSTCATEGORY.SelectedValue = dt.Rows[0]["COSTCATEGORY"].ToString();
                txtCOSTCATEGORY.Text = dt.Rows[0]["COSTCATEGORY"].ToString();
                if (hfResult.Value == "1")   //区分只有在下拉选择物料名称后执行该方法，其他时候，如提交时不执行该方法
                {
                    if (int.Parse(dt.Rows[0]["QUANTITY"].ToString()) > int.Parse(dt.Rows[0]["USEDQUANTITY"].ToString()))   //判断当前行数据是否有下过PO单
                    {
                        int Qty = int.Parse(dt.Rows[0]["QUANTITY"].ToString()) - int.Parse(dt.Rows[0]["USEDQUANTITY"].ToString());
                        txtHORTFALL.Text = Qty.ToString();
                    }
                }
                //if (int.Parse(dt.Rows[0]["USEDQUANTITY"].ToString()) == 0)
                //{
                //    txtHORTFALL.Text = dt.Rows[0]["QUANTITY"].ToString();
                //}
                txtPRAMOUNT.Text = dt.Rows[0]["ESTIMATEDPRICE"].ToString();  //PR申请金额
                txtPRINfo.Text = "PR单号：" + dt.Rows[0]["DOCUMENTNO"].ToString() + ",PN：" + dt.Rows[0]["PRODUCTLINE"].ToString() + ",CC：" + dt.Rows[0]["COSTCENTER"].ToString() + ",Requestor：" + dt.Rows[0]["APPLICANT"].ToString();
                txtPRRequester.Text = dt.Rows[0]["APPLICANT"].ToString().Trim();
                txtPRRequesterAccount.Text = GetApplicantAccount(dt.Rows[0]["APPLICANT"].ToString().Trim());
                txtPartNO.Text = dt.Rows[0]["PRODUCTNO"].ToString();
                txtUM.Text = "PC";
            }
            else
            {
                txtITEMNUMBER.Text = "";
                txtPRAMOUNT.Text = "";
                txtPRINfo.Text = "";
                txtPRRequester.Text = "";
                txtPRRequesterAccount.Text = "";
                txtSPEC.Text = "";
                txtHORTFALL.Text = "";
                txtPartNO.Text = "";
             
            }
            //txtMATERIALNAME.Text = ddlMaterial.SelectedItem.Text;
            //txtCOSTCATEGORY.Text = ddlCOSTCATEGORY.SelectedValue;
        }

        protected void fld_detail_PROC_PO_DT_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            UserInfo userInfo = Page.FindControl("UserInfo1") as UserInfo;
            userInfo.DeleteRow(fld_detail_PROC_PO_DT, e);
        }

        protected void lnk_LoadPayMent_Click(object sender, EventArgs e)
        {
            BindPayMent();            
        }
        public void BindPayMent()
        {
            if (fld_SUPPLIERNAME.Text != "")
            {
                string StrSQL = "select b.ct_desc,b.ct_code from dbo.SYNC_SUPPLIERINFORMATION a inner join dbo.SYNC_PARYMENT b on a.vd_cr_terms=b.ct_code where a.ad_name='" + fld_SUPPLIERNAME.Text.Trim() + "' ";
                DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(StrSQL);

                string SQL = "select distinct ct_desc,ct_code from SYNC_PARYMENT";
                DataTable dtAll = DataAccess.Instance("BizDB").ExecuteDataTable(SQL);
                fld_PAYMENT.Items.Clear();
                fld_PAYMENT.AppendDataBoundItems = true;
                fld_PAYMENT.Items.Insert(0, new ListItem("Other", "0"));
                fld_PAYMENT.DataSource = dtAll;
                fld_PAYMENT.DataTextField = "ct_code";
                fld_PAYMENT.DataValueField = "ct_code";
                fld_PAYMENT.DataBind();
                if (dt.Rows.Count > 0)
                {
                    fld_PAYMENT.SelectedValue = dt.Rows[0]["ct_code"].ToString().Trim();
                }
            }
        }

        //protected void fld_PAYMENT_SelectedIndexChanged(object sender, EventArgs e)    
        //{
        //    string SQL = "select distinct ct_desc,ct_code from SYNC_PARYMENT where ct_code='" + fld_PAYMENT.SelectedValue.Trim() + "'";
        //    DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(SQL);
        //    if (dt.Rows.Count > 0)
        //    {
        //        fld_OTHERPAYMENT.Text = dt.Rows[0]["ct_desc"].ToString();
        //    }
        //}

        protected void fld_detail_PROC_PO_DT_PreRender(object sender, EventArgs e)
        {
            foreach (RepeaterItem ri in this.fld_detail_PROC_PO_DT.Items)
            {
                RepeaterItem currentItem = ri;
                 
                #region 绑定物料名称
                DropDownList ddlMATERIALNAME = currentItem.FindControl("ddl_MATERIALNAME") as DropDownList;
                ddlMATERIALNAME.Attributes.Remove("OnSelectedIndexChanged");
                ddlMATERIALNAME.Items.Clear();
                ddlMATERIALNAME.Items.Insert(0, new ListItem("---请选择---", ""));
                string StrSQL = "";
                if (fld_PONO.Text.Contains(","))
                {
                    string[] sz = fld_PONO.Text.Split(',');
                    string str = "";
                    foreach (string ss in sz)
                    {
                        str += " or DOCUMENTNO= '" + ss + "'";                        
                    }
                    string strInn = str.Substring(3);
                    StrSQL = "select  P.ID,P.PRODUCTNAME,M.DOCUMENTNO from PROC_PURCHASEREQUEST as M inner join PROC_PURCHASEREQUEST_DT as P on"
                                  + "  P.FORMID=M.FORMID where P.STATUS=0 and " + (strInn) + "";  
                }
                else
                {
                    StrSQL = "select ID,PRODUCTNAME from PROC_PURCHASEREQUEST_DT where FORMID='" + fld_PRFORMID.Text.Trim() + "'  and Status=0";
                    //string StrSQL = "select ID,PRODUCTNAME from PROC_PURCHASEREQUEST_DT where FORMID='" + fld_PRFORMID.Text.Trim() + "' and Status=0";
                }               
                DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(StrSQL);
                ddlMATERIALNAME.DataSource = dt;
                ddlMATERIALNAME.DataTextField = "PRODUCTNAME";
                if (fld_PONO.Text.Contains(","))
                {
                    ddlMATERIALNAME.DataValueField = "DOCUMENTNO";
                }
                else
                {
                    ddlMATERIALNAME.DataValueField = "ID";
                }             
                ddlMATERIALNAME.DataBind();
                #endregion

                #region
                //DropDownList ddlCOSTCATEGORY = currentItem.FindControl("COSTCATEGORY") as DropDownList;
                //ddlCOSTCATEGORY.Items.Clear();
                //ddlCOSTCATEGORY.Items.Insert(0, new ListItem("---请选择---", ""));
                //ddlCOSTCATEGORY.Items.Insert(1, new ListItem("Repeatable", "Repeatable"));
                //ddlCOSTCATEGORY.Items.Insert(2, new ListItem("Discrete", "Discrete"));
                
                #endregion

                try
                {
                    DropDownList ddlName = ((DropDownList)ri.FindControl("ddl_MATERIALNAME"));
                    //DropDownList ddlType = ((DropDownList)ri.FindControl("ddl_MATERIALTYPE"));

                    //DropDownList COSTCATEGORY = (DropDownList)ri.FindControl("COSTCATEGORY");  //成本类别
                    //string  selectText3 = ((TextBox)ri.FindControl("fld_COSTCATEGORY")).Text;

                    string selectText = ((TextBox)ri.FindControl("fld_MATERIALNAME")).Text;
                    string selectText2 = ((TextBox)ri.FindControl("fld_MATERIALTYPE")).Text;
                    if (selectText != "")
                    {
                        ddlName.Items.FindByText(selectText).Selected = true;
                    }
                    //if (selectText2 != "")
                    //{
                    //    ddlType.Items.FindByText(selectText2).Selected = true;
                    //}
                    //if (selectText3 != "")
                    //{
                    //    COSTCATEGORY.Items.Clear();
                    //    COSTCATEGORY.Items.FindByText(selectText3).Selected = true;
                    //}
                }
                catch (Exception ex)
                {
                    string strMessage = ex.Message;
                }

              
            }
        }

        //protected void fld_PAYMENT_PreRender(object sender, EventArgs e)
        //{
        //    BindPayMent();
        //}

        /// <summary>
        /// 绑定币种
        /// </summary>
        public void BindCurrency()
        {
            string strSql = "select CURRENCY from dbo.SYNC_CURRENCY where ACTIVE=1";
            DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
            fld_CURRENCY.Items.Clear();
            //fld_CURRENCY.Items.Insert(0, new ListItem("---请选择---", ""));
            fld_CURRENCY.DataSource = dt;
            fld_CURRENCY.DataTextField = "CURRENCY";
            fld_CURRENCY.DataValueField = "CURRENCY";
            fld_CURRENCY.DataBind();
        }
        /// <summary>
        /// 绑定税别
        /// </summary>
        public void BindTax()
        {
            string strSql = "select TAXCLASSDESCRIPTION from dbo.SYNC_TAX";
            DataTable dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
            //fld_TAXCATEGORY.AppendDataBoundItems = true;
            //fld_TAXCATEGORY.Items.Clear();           
            fld_TAXCATEGORY.DataSource = dt;
            fld_TAXCATEGORY.DataTextField = "TAXCLASSDESCRIPTION";
            fld_TAXCATEGORY.DataValueField = "TAXCLASSDESCRIPTION";
            fld_TAXCATEGORY.DataBind();
            fld_TAXCATEGORY.Items.Insert(0, new ListItem("---请选择税别---", ""));
        }
        protected void Button3_Click(object sender, EventArgs e)
        {                 
            foreach (RepeaterItem ri in fld_detail_PROC_PO_DT.Items)
            {
                int TotalQty = 0;     
                int i_Qty = 0;                
                string RowID = ((DropDownList)ri.FindControl("ddl_MATERIALNAME")).SelectedValue;    //PR行号              
                string MaterialName = ((TextBox)ri.FindControl("fld_MATERIALNAME")).Text;    //物料名称                
                string bugCode = ((TextBox)ri.FindControl("fld_BUDGETNUMBER")).Text;   //预算编号
                double amount = ConvertUtil.ToDouble(((TextBox)ri.FindControl("fld_TOTALCOST")).Text);
                string CurrentQty = ((TextBox)ri.FindControl("fld_SHORTFALL")).Text;   //当前行订单量    

                if (fld_PONO.Text.Contains(","))
                {
                    //string[] fm = fld_PRFORMID.Text.Split(',');
                    //string str = "";
                    //foreach (string formId in fm)
                    //{
                        //str += " or DOCUMENTNO= '" + ss + "'";           
                        bool strName = GetPRDetail(MaterialName, CurrentQty);
                        int UsedQty = int.Parse(hfPRUsedQty.Value);       //PR中已使用的订单量
                        if (strName == true)
                        {
                            i_Qty = int.Parse(CurrentQty);   //当前输入的数量
                            TotalQty += i_Qty;
                        }
                        if (int.Parse(hfPRQty.Value.Trim()) == TotalQty)    //判断如果第一次用户输入的数量就与PR的总数量相等时，执行该判断
                        {
                            bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, hfCurrFormID.Value.Trim());   //
                        }
                        if (int.Parse(hfPRQty.Value.Trim()) == TotalQty + UsedQty)   //判断如果当前输入的数量加上已使用的数据，刚好等于PR的总数量，则更新行数据状态
                        {
                            bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, hfCurrFormID.Value.Trim());
                        }
                        if (int.Parse(hfPRQty.Value.Trim()) > TotalQty)   //判断如果当前输入的数量小于PR的总数量时，则更新当前输入的数量。
                        {
                            bool IsSuccess = _pr.UpdateRowsUsedQtyAndPR(bugCode, hfCurrFormID.Value.Trim(), TotalQty + UsedQty, MaterialName);
                        }
                    //}
                  
                }
                else
                {

                    bool strName = GetPRData(RowID, MaterialName, CurrentQty);
                    int UsedQty = int.Parse(hfPRUsedQty.Value);       //PR中已使用的订单量
                    if (strName == true)
                    {
                        i_Qty = int.Parse(CurrentQty);   //当前输入的数量
                        TotalQty += i_Qty;
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty)    //判断如果第一次用户输入的数量就与PR的总数量相等时，执行该判断
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, fld_PRFORMID.Text.Trim());   //
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) == TotalQty + UsedQty)   //判断如果当前输入的数量加上已使用的数据，刚好等于PR的总数量，则更新行数据状态
                    {
                        bool IsSuccessMessage = _pr.UpdateRowsStatus(bugCode, fld_PRFORMID.Text.Trim());
                    }
                    if (int.Parse(hfPRQty.Value.Trim()) > TotalQty)   //判断如果当前输入的数量小于PR的总数量时，则更新当前输入的数量。
                    {
                        bool IsSuccess = _pr.UpdateRowsUsedQty(bugCode, fld_PRFORMID.Text.Trim(), TotalQty + UsedQty, int.Parse(RowID));
                    }
                }
            }
        }


        /// <summary>
        /// 根据当前用户下单的数量小于PR的总数量，返回状态值为True，用于更新PR明细表中的已使用数量字段信息
        /// </summary>
        /// <param name="LineValue"></param>
        /// <param name="MaterialName"></param>
        /// <param name="UsedQty"></param>
        /// <returns></returns>
        public bool GetPRData(string LineValue, string MaterialName,string UsedQty)
        {
            bool strResult = false;
            try
            {
                DataTable dt = null;
                string strSql = "select T.ITEMNUMBER,T.SPEC,T.COSTCATEGORY,P.DOCUMENTNO,T.QUANTITY,T.CAPEXITEM,T.PRODUCTNAME,T.USEDQUANTITY from PROC_PURCHASEREQUEST_DT as T "
                                + " inner join dbo.PROC_PURCHASEREQUEST P on P.FORMID=T.FORMID "
                                + "  where DOCUMENTNO='" + fld_PONO.Text.Trim() + "' and ID='" + LineValue.Trim() + "'";                               
                dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
                if (dt.Rows.Count > 0)
                {
                    //strResult = dt.Rows[0]["ITEMDECRIPTION"].ToString().Trim();
                    string strQty = dt.Rows[0]["QUANTITY"].ToString().Trim();
                    string strUsedQty = dt.Rows[0]["USEDQUANTITY"].ToString().Trim();
                    hfPRQty.Value = strQty.Trim();
                    hfPRUsedQty.Value = strUsedQty.Trim();
                    if (int.Parse(strQty) > int.Parse(UsedQty))   //判断当前用户下单的数量小于PR的总数量，返回状态值为True，用于更新PR明细表中的已使用数量字段信息
                    {
                        strResult = true;
                    }
                }
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return strResult;

        }

        /// <summary>
        /// 根据当前用户下单的数量小于PR的总数量，返回状态值为True，用于更新PR明细表中的已使用数量字段信息
        /// </summary>
        /// <param name="LineValue"></param>
        /// <param name="MaterialName"></param>
        /// <param name="UsedQty"></param>
        /// <returns></returns>
        public bool GetPRDetail( string MaterialName, string UsedQty)
        {
            bool strResult = false;
            try
            {
                string[] fm = fld_PRFORMID.Text.Split(',');
                string str = "";
                foreach (string formId in fm)
                {
                    DataTable dt = null;
                    string strSql = "select T.ITEMNUMBER,T.SPEC,T.COSTCATEGORY,P.DOCUMENTNO,T.QUANTITY,T.CAPEXITEM,T.PRODUCTNAME,T.USEDQUANTITY,T.PRODUCTNAME from PROC_PURCHASEREQUEST_DT as T "
                                    + " inner join dbo.PROC_PURCHASEREQUEST P on P.FORMID=T.FORMID "
                                    + "  where P.FORMID='" + formId.Trim() + "' and PRODUCTNAME='" + MaterialName.Trim() + "'";
                    dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
                    if (dt.Rows.Count > 0)
                    {
                        string strQty = dt.Rows[0]["QUANTITY"].ToString().Trim();
                        string strUsedQty = dt.Rows[0]["USEDQUANTITY"].ToString().Trim();
                        hfPRQty.Value = strQty.Trim();
                        hfPRUsedQty.Value = strUsedQty.Trim();
                        hfCurrFormID.Value = formId;
                        if (int.Parse(strQty) > int.Parse(UsedQty))   //判断当前用户下单的数量小于PR的总数量，返回状态值为True，用于更新PR明细表中的已使用数量字段信息
                        {
                            strResult = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }
            return strResult;

        }

        //获取PR申请人账号
        public string GetApplicantAccount(string strPRRequester)
        {
            string strApplicantAccount = "";
            string strSql = "select LOGINNAME from dbo.COM_USER where CNNAME='" + strPRRequester.Trim() + "'";
            DataTable  dt = DataAccess.Instance("BizDB").ExecuteDataTable(strSql);
            if (dt.Rows.Count > 0)
            {
                strApplicantAccount = "vast/" + dt.Rows[0]["LOGINNAME"].ToString().Trim();
            }
            return strApplicantAccount;
        }
    }
}